package com.yipinhouse.reception.app.apiImpl;
import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.house.client.*;
import com.yipinhouse.house.client.param.EsSearchEstateParam;
import com.yipinhouse.house.client.param.PagePremisesParam;
import com.yipinhouse.house.client.param.ResoldApartmentEsSearchParam;
import com.yipinhouse.house.client.param.SearchResoldHouseParam;
import com.yipinhouse.house.client.result.*;
import com.yipinhouse.reception.client.HouseWebQueryClient;
import com.yipinhouse.reception.client.param.EsSearchEstateWebParam;
import com.yipinhouse.reception.client.param.PagePremisesWebParam;
import com.yipinhouse.reception.client.param.ResoldApartmentEsSearchWebParam;
import com.yipinhouse.reception.client.param.SearchResoldHouseWebParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/reception")
public class HouseWebQueryApiImpl implements HouseWebQueryClient {

    @Resource
    private NewHouseQueryClient newHouseQueryClient;

    @Resource
    private ResoldHouseQueryClient resoldHouseQueryClient;

    @Resource
    private ResoldApartmentQueryClient resoldApartmentQueryClient;

    @Resource
    private EstateQueryClient estateQueryClient;

    @Resource
    private PremisesQueryClient premisesQueryClient;

    @Resource
    private ApartmentClient apartmentClient;

    @Override
    public Result orderHouse(Integer id) {
        Result result = newHouseQueryClient.orderHouse(id);
        return result;
    }

    @Override
    public Result saleHouse(Integer houseId) {
        Result result = newHouseQueryClient.saleHouse(houseId);
        return result;
    }

    @Override
    public Result<List<ResoldApartmentListResultInfo>> resoldApartmentEsSearch(ResoldApartmentEsSearchWebParam resoldApartmentEsSearchParam) {
        ResoldApartmentEsSearchParam resoldParam = BeanUtil.copyProperties(resoldApartmentEsSearchParam, ResoldApartmentEsSearchParam.class);
        Result<List<ResoldApartmentListResultInfo>> result = resoldApartmentQueryClient.resoldApartmentEsSearch(resoldParam);
        return result;
    }

    @Override
    public Result<ResoldApartmentInfoResult> getResoldApartmentInfo(Integer houseId) {
        Result<ResoldApartmentInfoResult> resoldApartmentInfo = resoldApartmentQueryClient.getResoldApartmentInfo(houseId);
        return resoldApartmentInfo;
    }

    @Override
    public Result<PageResoldHouseInfo> searchResoldHouse(SearchResoldHouseWebParam param) {
        SearchResoldHouseParam searchResoldHouseParam = BeanUtil.copyProperties(param, SearchResoldHouseParam.class);
        Result<PageResoldHouseInfo> pageResoldHouseInfoResult = resoldHouseQueryClient.searchResoldHouse(searchResoldHouseParam);
        return pageResoldHouseInfoResult;
    }

    @Override
    public Result<String> checkHouseStatus(Integer houseId) {
        Result<String> stringResult = resoldHouseQueryClient.checkHouseStatus(houseId);
        return stringResult;
    }

    @Override
    public Result<ResoldHousingResult> getResoldHouseInfo(Integer houseId) {
        Result<ResoldHousingResult> resoldHouseInfo = resoldHouseQueryClient.getResoldHouseInfo(houseId);
        return resoldHouseInfo;
    }

    @Override
    public Result<PagePremisesResultInfo> searchPremises(PagePremisesWebParam param) {
        PagePremisesParam pagePremisesParam = BeanUtil.copyProperties(param, PagePremisesParam.class);
        Result<PagePremisesResultInfo> result = premisesQueryClient.searchPremises(pagePremisesParam);
        return result;
    }

    @Override
    public Result<ThisPremisesResultInfo> searchPremisesById(Integer id) {
        Result<ThisPremisesResultInfo>  premises = premisesQueryClient.searchPremisesById(id);
        return premises;
    }

    @Override
    public Result<List<ApartmentResultInfo>> searchApartment(Integer buildingId) {
        Result<List<ApartmentResultInfo>>  result = apartmentClient.searchApartment(buildingId);
        return result;
    }


    @Override
    public Result<PageEstateResultInfo> esSearchEstate(EsSearchEstateWebParam param) {
        EsSearchEstateParam esSearchEstateParam = BeanUtil.copyProperties(param, EsSearchEstateParam.class);
        Result<PageEstateResultInfo> pageEstateResultInfoResult = estateQueryClient.esSearchEstate(esSearchEstateParam);
        return pageEstateResultInfoResult;
    }

    @Override
    public Result<EstateResultInfo> checkEstate(Integer estateId) {
        Result<EstateResultInfo> estateResultInfoResult = estateQueryClient.checkEstate(estateId);
        return estateResultInfoResult;
    }
}
